package com.aaa.controller;

import com.aaa.entity.Drugstore;
import com.aaa.entity.SysLog;
import com.aaa.mapper.SysLogMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * 系统日志相关接口
 */
@RestController
@RequestMapping("/sysLog")
public class SysLogController {

    @Resource
    private SysLogMapper sysLogMapper;

    /**
     * 分页查询系统日志
     */
    @RequestMapping("/selectPage")
    public Object selectPage(SysLog sysLog,
                             @RequestParam(defaultValue = "1") Integer page,
                             @RequestParam(defaultValue = "10") Integer limit) {
        PageHelper.startPage(page, limit);
        List<SysLog> list = sysLogMapper.selectList();
        PageInfo<SysLog> pageInfo = new PageInfo<>(list);
        Map<String, Object> data = new HashMap<String, Object>();
        //这是layui要求返回的json数据格式
        data.put("code", 0);
        data.put("msg", "");
        //将全部数据的条数作为count传给前台（一共多少条）
        data.put("count", pageInfo.getTotal());
        //将分页后的数据返回（每页要显示的数据）
        data.put("data", pageInfo.getList());
        return data;
    }

}
